package cn.yunhe.controller;

import cn.yunhe.model.User;
import cn.yunhe.service.IUserService;
import com.github.pagehelper.PageHelper;
import com.sun.xml.internal.xsom.impl.ListSimpleTypeImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;


import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @描述
 * @参数 $params$
 * @返回值 $return$
 * @创建人 lihui
 * @创建时间 $date$
 * @修改人和其它信息
 */
@Controller
@SessionAttributes( names ={"user","list"})
@RequestMapping("/login")
public class UserAction {

    @Resource(name = "userService")
    private IUserService userService;


    @RequestMapping("/findAll")
    public ModelAndView findAll(@RequestParam int page,@RequestParam int limit) {
        System.out.println("jinlai"+page+limit);
        PageHelper.startPage(page,limit);
        List<User> list = userService.findalluser();
        int code=0;
       // String msg="";
        int count=100;
        ModelAndView mv = new ModelAndView();
        mv.setView(new MappingJackson2JsonView());
        mv.addObject("code",code);
        mv.addObject("page",2);
        mv.addObject("count",count);
        mv.addObject("data",list);
        return mv;

    }
    @RequestMapping("/login")
    public ModelAndView tologin(){
        ModelAndView mv = new ModelAndView();
        List<User> list = new ArrayList<User>();
        User user = new User();
        user.setName("李sf");
        User user1 = new User();
        user1.setName("李发");
        User user2 = new User();
        user2.setName("李身份");
        User user3 = new User();
        user3.setName("李关");
        User user4 = new User();
        user4.setName("李好");
        list.add(user);
        list.add(user1);
        list.add(user2);
        list.add(user3);
        list.add(user4);
        user.setId(21);
        user.setHiredate(new Date());
        mv.addObject("user",user);
        mv.addObject("list",list);
        mv.setViewName("index");
        return mv;
    }

}
